package com.lianwei.hospital.Service.Impl;

import com.lianwei.hospital.Service.LiveInfoService;
import com.lianwei.hospital.mapper.LiveInfoMapper;
import com.lianwei.hospital.module.entity.IllInfo;
import com.lianwei.hospital.module.entity.LiveInfo;
import com.lianwei.hospital.module.vo.LiveVO;
import com.lianwei.hospital.utils.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("LiveInfoService")
public class LiveInfoImpl implements LiveInfoService {
    @Autowired
    LiveInfoMapper liveInfoMapper;

    @Override
    public LiveInfo selectByPrimaryKey(Long id) throws Exception {
        return liveInfoMapper.selectByPrimaryKey(Math.toIntExact(id));
    }

    @Override
    public boolean insert(LiveInfo liveInfo) throws Exception {
        return liveInfoMapper.insert(liveInfo)>0;
    }

    @Override
    public List<LiveInfo> selectAll() throws Exception {
        return liveInfoMapper.selectAll();
    }

    @Override
    public boolean deleteByPrimaryKey(Long id) throws Exception {
        return liveInfoMapper.deleteByPrimaryKey(Math.toIntExact(id))>0;
    }

    @Override
    public boolean updateByPrimaryKey(LiveInfo liveInfo) throws Exception {
        return liveInfoMapper.updateByPrimaryKey(liveInfo)>0;
    }

    @Override
    public PageUtil<LiveInfo> findPage(LiveVO query) throws Exception {
        /*
         * 1.获取总记录数
         * 2.如果总记录数 > 0 查询数据
         *  将数据封装到PageUtil
         * 否则，返回null
         */
        int count=liveInfoMapper.countBySelectActive(query);
        if (count>0){
            List<LiveInfo> data=liveInfoMapper.selectListBySelectActive(query);
            return new PageUtil<>(query.getCurrentPage(),query.getPageSize(),count,data);
        }
        return null;
    }
}
